<?php

namespace app\service;

use app\model\Page as PageModel;

class PageService
{
    protected $model;

    public function __construct()
    {
        $this->model = app()->make(PageModel::class);
    }

    /**
     * @param $route
     * @return ArticleModel|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function queryDetail($route)
    {
        if (is_numeric($route)) {
            $where = ['id' => $route];
        } else {
            $where = ['route' => $route];
        }
        $article = $this->model->where($where)->find();

        if (!empty($article['content'])) {
            $article['content'] = str_replace("'", "\"", $article['content']);
        }
        return $article;
    }
}